﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Follow3DTarget : MonoBehaviour {
    public GameObject Target;
    public float xOffset;
    public float yOffset;

    private RectTransform rectTransform;

    private void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
    }

    void Update()
    {
        if (Target == null)
            return;
        Vector2 player2DPosition = Camera.main.WorldToScreenPoint(Target.transform.position);
        rectTransform.position = player2DPosition + new Vector2(xOffset, yOffset);

        var outScreen = player2DPosition.x > Screen.width || player2DPosition.x < 0 || player2DPosition.y > Screen.height || player2DPosition.y < 0;
        rectTransform.gameObject.SetActive(!outScreen);//血条超出屏幕就不显示
    }
}
